<template>
  <div>
    <el-row :gutter="24">
      <el-col :span="8" :offset="8">
        <div class="grid-content"></div>
      </el-col>
    </el-row>
    <el-row :gutter="24">
      <el-col :span="8" :offset="8">
        <el-input
          v-model="loginForm.username"
          placeholder="请输入内容"
        ></el-input>
        <el-input
          v-model="loginForm.userpassword"
          placeholder="请输入密码"
          show-password
        ></el-input>
        <el-button type="primary" @click="login()">登录</el-button>
      </el-col>
    </el-row>
  </div>
</template>

<script>
export default {
  name: "UserLogin",
  data() {
    return {
      loginForm: {
        username: "",
        userpassword: "",
      },
    };
  },
  methods: {
    login() {
      let that = this;
      this.axios({
        Headers: {
          "Content-Type": "application/json",
        },
        method: "post",
        url: this.$constant.url + "/user/login",
        xhrFields: {
          withCredentials: true,
        },
        data: that.loginForm,
      }).then(({ data }) => {
        if (data.code == 100) {
          sessionStorage.setItem('userLogin',data.data);
          this.$store.dispatch("asyncUpdateUser",{name:this.loginForm.username})
          that.$router.push({ path: "/user/" });
        }
      });
    },
  },
};
</script>

<style>
</style>